Skip to content

When creating a process, set the FD_CLOEXEC flag on the master PTY#193

Open
romainreignier wants to merge 1 commit intoxqms:masterfrom
romainreignier:close_master_pty_on_exec
Open

When creating a process, set the FD_CLOEXEC flag on the master PTY#193
romainreignier wants to merge 1 commit intoxqms:masterfrom
romainreignier:close_master_pty_on_exec

Conversation

@romainreignier
Copy link
Contributor

To avoid a leak of the PTY file descriptor in the child process, the ROS Node.

This allows to close the master fd in the child process after execvp() is executed.

From man fcntl:

FD_CLOEXEC, the close-on-exec flag. If the FD_CLOEXEC bit is set,
the file descriptor will automatically be closed during a successful
execve(2).

Before this, the child processes (the shim, then the ROS node) inherited all the master and stderr_master file descriptors of the other already-running nodes from the parent process.

For example, with a launch file with 10 nodes, running lsof -p $PID with the pid of the nodes, there was a growing number of /dev/ptmx lines for the ROS nodes process. While when launched with roslaunch, there is node.

Command used: sudo lsof -p $PID | grep ptmx | wc -l

Node number Number of /dev/ptmx
1 0
2 2
3 4
4 6
10 18

With this fix, the number is always zero.

To avoid a leak of the PTY file descriptor in the child process, the ROS Node.

This allows to close the master fd in the child process after execvp()
is executed.

From man fcntl:

> FD_CLOEXEC, the close-on-exec flag.  If the FD_CLOEXEC bit is set,
> the file descriptor will automatically be closed during a successful
> execve(2).

Before this, the child processes (the shim, then the ROS node) inherited
all the `master` and `stderr_master` file descriptors of the other
already-running nodes from the parent process.

For example, with a launch file with 10 nodes, running `lsof -p $PID` with
the pid of the nodes, there was a growing number of `/dev/ptmx` lines for
the ROS nodes process. While when launched with roslaunch, there is node.

Command used: `sudo lsof -p $PID | grep ptmx | wc -l`

| Node number | Number of /dev/ptmx |
|-------------|---------------------|
| 1 | 0 |
| 2 | 2 |
| 3 | 4 |
| 4 | 6 |
| 10 | 18 |

With this fix, the number is always zero.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant